package com.letoken.platform.pub.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;

import java.util.HashMap;
import java.util.Map;

/**
 * @author wyl
 * 代币处理-状态 定义枚举
 */
public enum TokenTransactionStatusEnum {

    /**
     * 代币处理-状态 定义枚举
     */
    PENDING(0, "正在处理"),
    COMPLETED(1, "已完成"),
    NETWORK_CONFIRM(2, "网络确认中"),
    FAIL(3, "失败"),
    ERROR(4, "异常");

    @EnumValue
    private Integer value;
    @JsonValue
    private String text;

    private static Map<String, TokenTransactionStatusEnum> pool = new HashMap<>();


    TokenTransactionStatusEnum(Integer value, String text) {
        this.value = value;
        this.text = text;
    }

    public static TokenTransactionStatusEnum valueOf(int value) {
        return pool.get(String.valueOf(value));
    }

    public Integer getValue() {
        return this.value;
    }

    public String getText() {
        return text;
    }

    public static boolean isSupport(String val) {
        for (TokenTransactionStatusEnum openState : values()) {
            if (openState.getValue().equals(val)) {
                return true;
            }
        }
        return false;
    }

    public static String getText(String val) {
        for (TokenTransactionStatusEnum openState : values()) {
            if (openState.getValue().equals(val)) {
                return openState.getText();
            }
        }
        return "";
    }

}
